<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="iso-8859-1"%>
<%--@elvariable id="command" type="com.google.code.sms.command.SearchCommand"--%>

<html><head>
        <%@ include file="head.jsp" %>
        <%@ include file="jquery.jsp" %>
    </head>
    <body class="mainframe bgcolor1">

        <h1>
            <img src="<spring:theme code="searchImage"/>" alt=""/>
            <span style="vertical-align: middle"><fmt:message key="search.title"/></span>
        </h1>

        <form:form commandName="command" method="post" action="search.view" name="searchForm">
            <table>
                <tr>
                    <td style="padding-left:0.25em"><form:input path="query" size="35"/></td>
                    <td style="padding-left:0.25em"><input type="submit" onclick="search(0)" value="<fmt:message key="search.search"/>"/></td>
                </tr>
            </table>

        </form:form>

        <c:if test="${command.indexBeingCreated}">
            <p class="warning"><fmt:message key="search.index"/></p>
        </c:if>

        <c:if test="${not command.indexBeingCreated and empty command.audioElements and empty command.videoElements and empty command.directoryElements}">
            <p class="warning"><fmt:message key="search.hits.none"/></p>
        </c:if>

        <c:if test="${not empty command.audioElements}">
            <h2><fmt:message key="search.hits.audio"/></h2>
            <table style="border-collapse:collapse">
                <c:forEach items="${command.audioElements}" var="match" varStatus="loopStatus">
                    
                    <c:url value="/main.view" var="mainUrl">
                        <c:param name="path" value="${match.parentPath}"/>
                    </c:url>

                    <tr class="audioElementRow" ${loopStatus.count > 5 ? "style='display:none'" : ""}>
                        <c:import url="playAddDownload.jsp">
                            <c:param name="id" value="${match.id}"/>
                            <c:param name="video" value="${match.video}"/>
                            <c:param name="playEnabled" value="${command.user.streamRole and not match.rootDirectory and not match.metaData.videoDirectory}"/>
                            <c:param name="addEnabled" value="${command.user.streamRole and not match.rootDirectory and not match.metaData.videoDirectory and not match.video}"/>
                            <c:param name="downloadEnabled" value="${command.user.downloadRole and not match.rootDirectory and not match.metaData.videoDirectory}"/>
                            <c:param name="asTable" value="true"/>
                        </c:import>
                        
                        <td ${loopStatus.count % 2 == 1 ? "class='bgcolor2'" : ""} style="padding-left:0.25em;padding-right:1.25em">
                            ${match.name}
                        </td>

                        <td ${loopStatus.count % 2 == 1 ? "class='bgcolor2'" : ""} style="padding-right:1.25em">
                            <a href="${mainUrl}"><span class="detail">${match.metaData.album}</span></a>
                        </td>

                        <td ${loopStatus.count % 2 == 1 ? "class='bgcolor2'" : ""} style="padding-right:0.25em">
                            <span class="detail">${match.metaData.artist}</span>
                        </td>
                        
                    </tr>

                </c:forEach>
            </table>
            <c:if test="${fn:length(command.audioElements) gt 5}">
                <div id="moreAudioElements" class="forward"><a href="#" onclick="$('.audioElementRow').show();
                            $('#moreAudioElements').hide();"><fmt:message key="search.hits.more"/></a></div>
                </c:if>
            </c:if>

        <c:if test="${not empty command.videoElements}">
            <h2><fmt:message key="search.hits.video"/></h2>
            <table style="border-collapse:collapse">
                <c:forEach items="${command.videoElements}" var="match" varStatus="loopStatus">

                    <c:url value="/main.view" var="mainUrl">
                        <c:param name="path" value="${match.parentPath}"/>
                    </c:url>

                    <tr class="videoElementRow" ${loopStatus.count > 5 ? "style='display:none'" : ""}>
                        <c:import url="playAddDownload.jsp">
                            <c:param name="id" value="${match.id}"/>
                            <c:param name="video" value="${match.video}"/>
                            <c:param name="playEnabled" value="${command.user.streamRole and not match.rootDirectory and not match.metaData.videoDirectory}"/>
                            <c:param name="addEnabled" value="${command.user.streamRole and not match.rootDirectory and not match.metaData.videoDirectory and not match.video}"/>
                            <c:param name="downloadEnabled" value="${command.user.downloadRole and not match.rootDirectory and not match.metaData.videoDirectory}"/>
                            <c:param name="asTable" value="true"/>
                        </c:import>

                        <td ${loopStatus.count % 2 == 1 ? "class='bgcolor2'" : ""} style="padding-left:0.25em;padding-right:1.25em">
                            ${match.name}
                        </td>
                        
                    </tr>

                </c:forEach>
            </table>
            <c:if test="${fn:length(command.videoElements) gt 5}">
                <div id="moreVideoElements" class="forward"><a href="#" onclick="$('.videoElementRow').show();
                            $('#moreVideoElements').hide();"><fmt:message key="search.hits.more"/></a></div>
                </c:if>
            </c:if>


        <c:if test="${not empty command.directoryElements}">
            <h2><fmt:message key="search.hits.directory"/></h2>
            <table style="border-collapse:collapse">
                <c:forEach items="${command.directoryElements}" var="match" varStatus="loopStatus">

                    <c:url value="/main.view" var="mainUrl">
                        <c:param name="path" value="${match.path}"/>
                    </c:url>

                    <tr class="directoryElementRow" ${loopStatus.count > 15 ? "style='display:none'" : ""}>
                        <c:import url="playAddDownload.jsp">
                            <c:param name="id" value="${match.id}"/>
                            <c:param name="video" value="${match.video}"/>
                            <c:param name="playEnabled" value="${command.user.streamRole and not match.rootDirectory and not match.metaData.videoDirectory}"/>
                            <c:param name="addEnabled" value="${command.user.streamRole and not match.rootDirectory and not match.metaData.videoDirectory and not match.video}"/>
                            <c:param name="downloadEnabled" value="${command.user.downloadRole and not match.rootDirectory and not match.metaData.videoDirectory}"/>
                            <c:param name="asTable" value="true"/>
                        </c:import>

                        <td ${loopStatus.count % 2 == 1 ? "class='bgcolor2'" : ""} style="padding-left:0.25em;padding-right:1.25em">
                            <a href="${mainUrl}">${match.name}</a>
                        </td>
                        
                    </tr>

                </c:forEach>
            </table>
            <c:if test="${fn:length(command.directoryElements) gt 15}">
                <div id="moreDirectoryElements" class="forward"><a href="#" onclick="$('.directoryElementRow').show();
                            $('#moreDirectoryElements').hide();"><fmt:message key="search.hits.more"/></a></div>
                </c:if>
            </c:if>

    </body></html>